{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "ee3a10de",
   "metadata": {},
   "source": [
    "## 测试目的：VL大模型的few-shots效果\n",
    "\n",
    "### 测试二：以系统提示词方式注入提取要求\n",
    "\n",
    "结论：成功！"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "5324231f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "```json\n",
      "{\n",
      "  \"栏目名\": \"九、二级单位业务主管领导 (只审批涉及一级及以上动火、三级及以上高处、二级及以上吊装作业):\",\n",
      "  \"手写意见\": \"\",\n",
      "  \"签名\": \"-红海\",\n",
      "  \"日期\": \"20S 年6月 日\"\n",
      "}\n",
      "```\n"
     ]
    }
   ],
   "source": [
    "import dashscope\n",
    "\n",
    "messages = [\n",
    "{\n",
    "    \"role\": \"system\",\n",
    "    \"content\": [\n",
    "    {\"text\": \"你一位观察型表格分析师。你能够仔细阅读并分析每个单元格的信息，确保不遗漏任何细节。 对于复杂的表单结构（如多层级分类、交叉项等），你能快速定位目标区域而不混淆相邻数据。\"},\n",
    "    {\"text\": \"提取图中提取“九、公司业务主管领导”所在单元格的['栏目名', '手写意见', '签名', '日期']，请你以JSON格式输出，并在该单元格不存在时返回空值，不要输出json代码段。\"}]\n",
    "},\n",
    "{\n",
    "    \"role\": \"user\",\n",
    "    \"content\": [\n",
    "        {\"image\": \"file://C:/Users/serap/Pictures/1_有签字.png\"},\n",
    "        {\"text\": \"\"}\n",
    "    ]\n",
    "},\n",
    "{\n",
    "    \"role\": \"assistant\",\n",
    "    \"content\": [\n",
    "    {\"text\": \"\"\"\n",
    "    {\n",
    "        \"栏目名\": \"九、二级单位业务主管领导（只审批涉及一级及以上动火、三级及以上高处、二级及以上吊装作业）\", \n",
    "        \"手写意见\": \"同意\", \n",
    "        \"签名\": \"张玉河\", \n",
    "        \"日期\": \"2015年4月2日\" \n",
    "    }\n",
    "    \"\"\"}]\n",
    "},\n",
    "{\n",
    "    \"role\": \"user\",\n",
    "    \"content\": [\n",
    "        {\"image\": \"file://C:/Users/serap/Pictures/2_没第九.jpg\"},\n",
    "        {\"text\": \"\"}\n",
    "    ]\n",
    "},\n",
    "{\n",
    "    \"role\": \"assistant\",\n",
    "    \"content\": [{\"text\": \"{}\"}]\n",
    "},\n",
    "{\n",
    "    \"role\": \"user\",\n",
    "    \"content\": [\n",
    "        {\"image\": \"file://C:/Users/serap/Pictures/3_无签字.png\"},\n",
    "        {\"text\": \"\"}\n",
    "    ]\n",
    "},\n",
    "{\n",
    "    \"role\": \"assistant\",\n",
    "    \"content\": [\n",
    "    {\"text\": \"\"\"\n",
    "    {\n",
    "        \"栏目名\": \"九、公司业务主管领导：(只审批涉及管线打开的特级动火作业)\",\n",
    "        \"手写意见\": \"\",\n",
    "        \"签名\": \"\",\n",
    "        \"日期\": \"\"\n",
    "    }\n",
    "    \"\"\"}]\n",
    "},\n",
    "{\n",
    "    \"role\": \"user\",\n",
    "    \"content\": [\n",
    "        {\"image\": \"file://C:/Users/serap/Pictures/4_测试5.jpg\"},\n",
    "        {\"text\": \"\"}\n",
    "    ]\n",
    "}\n",
    "]\n",
    "\n",
    "\n",
    "response = dashscope.MultiModalConversation.call(\n",
    "    api_key=\"sk-0e687ddcf0164a6fb66c1096447223c4\",  # 阿里百炼大模型API获取：https://bailian.console.aliyun.com/?apiKey=1#/api-key\n",
    "    model = 'qwen2.5-vl-32b-instruct',  # 此处以qwen-vl-max-latest为例，可按需更换模型名称。模型列表：https://help.aliyun.com/zh/model-studio/models\n",
    "    vl_high_resolution_images=True,\n",
    "    messages = messages\n",
    ")\n",
    "print(response.output.choices[0].message.content[0][\"text\"])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5df05f81",
   "metadata": {},
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.19"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
